package com.leetcode.weekly.contest.no234th;

import java.util.HashSet;
import java.util.Set;

/**
 * @author 覃国强
 * @date 2021-03-28 10:37
 */
public class A01_字符串中不同整数的数目 {

  public static void main(String[] args) {
    Solution solution = new Solution();
    String word = "167278959591294";
    int i = solution.numDifferentIntegers(word);
    System.out.println(i);
  }

  static
  class Solution {
    public int numDifferentIntegers(String word) {
      if (word == null || word.length() == 0) {
        return 0;
      }
      String[] split = word.split("\\D+");
      Set<String> set = new HashSet<>();
      for (String str : split) {
        if (str.length() > 0) {
          str = removeLeadingZero(str);
          set.add(str);
        }
      }
      return set.size();
    }

    private String removeLeadingZero(String str) {
      int index = 0;
      for (; index < str.length(); ++index) {
        if (str.charAt(index) != '0') {
          break;
        }
      }
      if (index == str.length()) {
        return "0";
      }
      return str.substring(index);
    }
  }



}
